#include "PropertyChangeAction.h"

namespace editor_core {

	PropertyChangeAction::PropertyChangeAction( IEntity* entity, const Property& changedProperty ) :
		m_entity( entity ),
		m_changedProperty( changedProperty ),
		m_newValue( changedProperty.GetValue() ),
		m_oldValue( changedProperty.GetValue() )
	{
		Property oldProperty( changedProperty );
		m_entity->TryUpdateProperty( oldProperty );
		m_oldValue = oldProperty.GetValue();
	}

	PropertyChangeAction::~PropertyChangeAction() {}

	bool PropertyChangeAction::Commit() {
		return m_entity->TryUpdateFromProperty( m_changedProperty );
	}

	void PropertyChangeAction::Rollback() {
		Property oldProperty( m_changedProperty );
		oldProperty.SetValue( m_oldValue );
		m_entity->TryUpdateFromProperty( oldProperty );
	}

	void PropertyChangeAction::Recommit() {
		m_entity->TryUpdateFromProperty( m_changedProperty );
	}
}
